package com.linkgie.galaxyframework.crypto.context;

import java.io.OutputStream;

import com.linkgie.galaxyframework.crypto.AsymmetricCipherService;
import com.linkgie.galaxyframework.crypto.PrivateKey;
import com.linkgie.galaxyframework.crypto.PublicKey;
import com.linkgie.galaxyframework.crypto.spi.AsymmetricCipherFuncSPI;
import com.linkgie.galaxyframework.crypto.spi.PrivateKeybytes;
import com.linkgie.galaxyframework.crypto.spi.PublicKeybytes;

public class AsymmetricCipherServiceImpl extends AsymmetricServiceBase<AsymmetricCipherFuncSPI>
		implements AsymmetricCipherService {

	public AsymmetricCipherServiceImpl(AsymmetricCipherFuncSPI innerService) {
		super(innerService);
	}

	@Override
	public byte[] encrypt(PublicKey key, byte[] plainBytes) {
		PublicKeybytes pubKeyBytes = ENCODING.decode(key);
		return INNSER_SERVICE.encrypt(pubKeyBytes, plainBytes);
	}

	@Override
	public byte[] encrypt(PublicKey key, byte[] plainBytes, int offset, int length) {
		PublicKeybytes pubKeyBytes = ENCODING.decode(key);
		return INNSER_SERVICE.encrypt(pubKeyBytes, plainBytes, offset, length);
	}

	@Override
	public int encrypt(PublicKey key, byte[] plainBytes, int offset, int length, OutputStream out) {
		PublicKeybytes pubKeyBytes = ENCODING.decode(key);
		return INNSER_SERVICE.encrypt(pubKeyBytes, plainBytes, offset, length, out);
	}

	@Override
	public byte[] encrypt(byte[] pubKeyBytes, byte[] plainBytes) {
		return INNSER_SERVICE.encrypt(pubKeyBytes, plainBytes);
	}

	@Override
	public byte[] encrypt(byte[] pubKeyBytes, byte[] plainBytes, int offset, int length) {
		return INNSER_SERVICE.encrypt(pubKeyBytes, plainBytes, offset, length);
	}

	@Override
	public int encrypt(byte[] pubKeyBytes, byte[] plainBytes, int offset, int length, OutputStream out) {
		return INNSER_SERVICE.encrypt(pubKeyBytes, plainBytes, offset, length, out);
	}

	@Override
	public byte[] decrypt(PrivateKey key, byte[] cipherBytes) {
		PrivateKeybytes privKeyBytes = ENCODING.decode(key);
		return INNSER_SERVICE.decrypt(privKeyBytes, cipherBytes);
	}

	@Override
	public byte[] decrypt(PrivateKey key, byte[] cipherBytes, int offset, int length) {
		PrivateKeybytes privKeyBytes = ENCODING.decode(key);
		return INNSER_SERVICE.decrypt(privKeyBytes, cipherBytes, offset, length);
	}

	@Override
	public int decrypt(PrivateKey key, byte[] cipherBytes, int offset, int length, OutputStream out) {
		PrivateKeybytes privKeyBytes = ENCODING.decode(key);
		return INNSER_SERVICE.decrypt(privKeyBytes, cipherBytes, offset, length, out);
	}
	
	@Override
	public byte[] decrypt(byte[] privKeyBytes, byte[] cipherBytes) {
		return INNSER_SERVICE.decrypt(privKeyBytes, cipherBytes);
	}
	
	@Override
	public byte[] decrypt(byte[] privKeyBytes, byte[] cipherBytes, int offset, int length) {
		return INNSER_SERVICE.decrypt(privKeyBytes, cipherBytes, offset, length);
	}
	
	@Override
	public int decrypt(byte[] privKeyBytes, byte[] cipherBytes, int offset, int length, OutputStream out) {
		return INNSER_SERVICE.decrypt(privKeyBytes, cipherBytes, offset, length, out);
	}

}
